package org.czl.leetCode1;


public class w {

    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
    public int rob(TreeNode root) {
        int[] res = dfs(root);
        return Math.max(res[0], res[1]);
    }
    int[] dfs(TreeNode root){
        if(root == null)
            return new int[]{0,0};
        int[] left = dfs(root.left);
        int[] right = dfs(root.right);
        int doo = left[1] + right[1] + root.val;
        int notDo = Math.max(left[0], left[1]) + Math.max(right[0], right[1]);
        return new int[]{doo, notDo};
    }
}
